/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vmcs.controller.statePattern;
/**
 *
 * @author Eileen
 */
class CoinReceiveState extends VmcsState {    
    
    private int ttlCoinRecv = 0;
    CoinReceiveState(TransactionController fsm){
        this.m_fsm = fsm;
    }
    @Override
    public void OnSelectDrink() {
        System.out.println("CoinReceiveState::On Select drink");
        m_fsm.setRefundAmount(ttlCoinRecv);
        m_fsm.getState(TransactionController.CHANGE_GIVE).OnSelectDrink();
        ttlCoinRecv = 0;
    }    
    @Override
    public void OnTerminate() {
        System.out.println("CoinReceiveState::On terminate");
        m_fsm.setRefundAmount(ttlCoinRecv);
        ttlCoinRecv = 0;
        m_fsm.getState(TransactionController.CHANGE_GIVE).OnTerminate();
    }    
    @Override
    public void OnGiveChange() {
        System.out.println("CoinReceiveStatez::On give change! -- This state is not valid. Throw exception if possible");
    }    
    @Override
    public void OnDispenseDrink() {
        System.out.println("CoinReceiveState::On dispense drink! --  This state is not valid. Throw exception if possible");
    }
    @Override
    public void OnMaintenance() {
        System.out.println("CoinReceiveState::On Maintenance mode");
        System.out.println("CoinReceiveState::On Select drink");
        m_fsm.setRefundAmount(ttlCoinRecv);
        ttlCoinRecv = 0;
        m_fsm.getState(TransactionController.CHANGE_GIVE).OnMaintenance();
    }
    @Override
    public void OnReceiveCoin() {
        System.out.println("CoinReceiveState::On Receive Coin");
        m_fsm.setActivateCoinPanel(true);
        
        final int price = m_fsm.getPrice();
        System.out.println("CoinReceiveState::Get Coin store to find the value of the coin.");
        
        double value = m_fsm.getCurrentCoinValue();
        ttlCoinRecv += value;//coin_inserted; 
        m_fsm.setTotalInsertedValue(ttlCoinRecv);
        System.out.println("CoinReceiveState::Total money recv is " + ttlCoinRecv + " and short of " + (price - ttlCoinRecv) );
        
        if(ttlCoinRecv>=price){
            m_fsm.setActivateCoinPanel(false);
            int refund = ttlCoinRecv - price;
            ttlCoinRecv = 0;
            m_fsm.setRefundAmount(refund);
            m_fsm.getState(TransactionController.DISPENSE_DRINK).OnDispenseDrink();
        }
    }
    @Override
    public void OnStoreCoin() {
        System.out.println("CoinReceiveState::On Receive Coin");
    }
}

